﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class BagEvent : DeventCenter
{
    public static string BAGITEMADD = "bagitemadd";

    public static string BAGITEMDEL = "bagitemdel";

    public static string BAGITEMCHANGE = "bagitemchagne";

    public static string BagItemMove = "bagitemmove";

    //===========================================

    Dictionary<string, DelCallBack> myDicEventType;

    public BagEvent()
    {
        myDicEventType = new Dictionary<string, DelCallBack>();
    }

    public override void AddListener(string eventType, DelCallBack handler)
    {
        if (!myDicEventType.ContainsKey(eventType))
        {
            myDicEventType.Add(eventType, null);
        }
        myDicEventType[eventType] += handler;
    }

    public override void RemoveListener(String eventType, DelCallBack handler)
    {
        if (myDicEventType.ContainsKey(eventType))
        {
            myDicEventType[eventType] -= handler;
        }
    }

    public override void RemoveAllListener()
    {
        myDicEventType.Clear();
    }

    public override void DispatchEvent(String eventType, Object data)
    {
        if (myDicEventType.TryGetValue(eventType, out DelCallBack del))
        {
            del?.Invoke(data);
        }

    }
}
